package com.class05.m_innerclass.b;

import com.class05.m_innerclass.a.Test;

public interface Person {
    void eat();//省略public abstract
}

class Student implements Person {
    @Override
    public void eat() {
        System.out.println("学生吃饭");
    }
}

class TestY {
    //    内部类
    static class Teacher implements Person {
        @Override
        public void eat() {
            System.out.println("老师吃饭");
        }
    }


    public void test() {
//       局部内部类：可以放在方法中、构造方法中、代码块中
        class Guide implements Person {
            @Override
            public void eat() {
                System.out.println("导员吃饭");
            }
        }
//        new Guide().eat();
    }


    public static void main(String[] args) {
        Person p = new Student();
        p.eat();
        Teacher teacher = new Teacher();
        teacher.eat();
        System.out.println("-------------------");
//        new TestY().test();
//        局部内部类无法被外部实例化
        new TestY().test();
        System.out.println("-------------------");
        TestY.test1(new Person() {
            @Override
            public void eat() {
                System.out.println("匿名内部类吃饭");
            }
        });
        System.out.println("-------------------");
        TestY.test2().eat();
    }

    public static void test1(Person p) {
        p.eat();
    }

    public static Person test2() {
//      Person p =  new Person() {
//           @Override
//           public void eat() {
//               System.out.println("匿名内部类吃饭");
//           }
//       };
//      return p;
        return new Person() {
            @Override
            public void eat() {
                System.out.println("匿名内部类吃饭");
            }
        };
    }

}
